home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / log3.zip / LOG.PAS < prev    next >
Pascal/Delphi Source File  |  1987-05-09  |  16KB  |  417 lines

  1. Program Log;
  2. (****************************************************************************)
  3. (*                                                                          *)
  4. (*                               LOG                                        *)
  5. (*                           Revision 2.0                                   *)
  6. (*             Written by Don Gancsos and Robert Wilcox                     *)
  7. (*                                                                          *)
  8. (*             A program which logs computer operation and calculates       *)
  9. (*             the elapsed time between log entries.                        *)
  10. (*             Logs date, time, elapsed time and comment to the             *)
  11. (*             file "TIME.LOG"                                              *)
  12. (*                                                                          *)
  13. (*                  Use: LOG comment                                        *)
  14. (*                                                                          *)
  15. (*             Modified by R. Wilcox 3-14-86                                *)
  16. (*                - Now puts log file in root directory of drive A          *)
  17. (*                  rather than in the logged-in directory.                 *)
  18. (*                - Uses command line (up to 50 characters) as comment.     *)
  19. (*                - Log file changed to 'TIME.LOG' (3-23-86)                *)
  20. (*             Rev 2.0 modifications 4-9-86                                 *)
  21. (*                - Uses random file allowing a "SHOW" program to           *)
  22. (*                  display start and end log entries with the              *)
  23. (*                  calculated elapsed time.                                *)
  24. (*                - Log file changed to 'NEWTIME.LOG'.                      *)
  25. (*                                                                          *)
  26. (*             Rev 3.0 modifications 5-10-87 by Rick Johnson                *)
  27. (*                                                                          *)
  28. (*                  Use: LOG <off|[comment] /a|/*>                          *)
  29. (*                                                                          *)
  30. (*                - Keeps log in random file 'TIME.LOG' in path             *)
  31. (*                  C:\UTILITY.                                             *)
  32. (*                - Random file records now store:                          *)
  33. (*                  1) Time category, e.g. 'B' for business.                *)
  34. (*                  2) Start date.                                          *)
  35. (*                  3) Start time.                                          *)
  36. (*                  4) End time.                                            *)
  37. (*                  5) Elapsed time (string).                               *)
  38. (*                  6) Elapsed time (real no.).                             *)
  39. (*                  8) Comment (up to 12 characters).                       *)
  40. (*                - Session terminated and elapsed time calculated          *)
  41. (*                  with 'LOG OFF' command.                                 *)
  42. (*                - Time category invoked with '/a' parameter where         *)
  43. (*                  'a' is any alpha character a through z.                 *)
  44. (*                - Time categories 'B' and 'P' noted as 'Business'         *)
  45. (*                  or 'Personal' use in program's screen messages          *)
  46. (*                - Times displayed and totaled with '/*' parameter         *)
  47. (*                  and optionally written to disk file:                    *)
  48. (*                  1) Text format for word processor or                    *)
  49. (*                  2) Comma-delimited for spreadsheet.                     *)
  50. (*                  SHOW.COM no longer needed.                              *)
  51. (*                                                                          *)
  52. (*                                                                          *)
  53. (****************************************************************************)
  54.  
  55.  
  56. Type
  57.   Datestring = string[8];
  58.   CommandString  = string[50];
  59.   CommentString = string[12];
  60.   Filename = string[24];
  61.   Registers    = record
  62.                 AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer;
  63.             End;
  64.  
  65. LogRec = Record
  66.   usage: char;              {usage type, i.e. business/personal}
  67.   start_date_log : Datestring;     {start date}
  68.   start_time_log : Datestring;     {start time}
  69.   end_time_log   : Datestring;     {end time}
  70.   elapsed_log    : Datestring;     {elapsed time}
  71.   comment        : CommentString;  {comment}
  72.   elapsed_real   : Real;           {elapsed time stored as real no.}
  73.   end;
  74.  
  75. Var
  76.   Mon, Day, Year : string[2];
  77.   logfile        : file of LogRec;
  78.   realtime       : Real;
  79.   Buffer         : CommandString;
  80.   CL             : CommandString absolute cseg:$80;
  81.   log_data       : logrec;
  82.   logoff         : boolean;
  83.  
  84. Const
  85.   logfilename    : filename = 'C:\UTILITY\TIME.LOG';
  86.  
  87. Function Date: Datestring;
  88. var
  89.   RSet   : Registers;
  90.   tempstring: Datestring;
  91.   i: Integer;
  92. Begin
  93.   With Rset do
  94.   Begin
  95.     AX   :=  $2A00;        { DOS get date function }
  96.     MSDos(RSet);
  97.     CX := cx mod 100;
  98.     str(CX:2,year);
  99.     str(Hi(DX):2,mon);
  100.     str(Lo(DX):2,day);
  101.   End;
  102.   tempstring := mon + '/' + day + '/' + year;
  103.    for i := 1 to 8 do
  104.      if tempstring[i] = ' ' then
  105.        tempstring[i] := '0';
  106. Date := tempstring;
  107. End;
  108.  
  109. Function Time: Datestring;
  110. var
  111.   RSet                 : registers;
  112.   hour, minute, second : string[2];
  113.   i                    : integer;
  114.   tempstring           : Datestring;
  115. Begin
  116.    rset.ax := $2C * 256;
  117.    MsDos(rset);
  118.    str((rset.cx div 256):2,hour);
  119.    str((rset.cx mod 256):2,minute);
  120.    str((rset.dx div 256):2,second);
  121.    tempstring := hour + ':' + minute + ':' + second;
  122.    for i := 1 to 8 do
  123.      if tempstring[i] = ' ' then
  124.        tempstring[i] := '0';
  125.    Time := tempstring;
  126. End;  {Time}
  127.  
  128. Function SecToString(secs: integer): Datestring;
  129. var
  130.   t: integer;
  131.   result: Datestring;
  132.   tempresult: Datestring;
  133. Begin
  134.   Str(secs div 3600:2,tempresult);
  135.   result := tempresult + ':';
  136.   t:= secs mod 3600;
  137.   Str(t div 60:2,tempresult);
  138.   result := result +tempresult + ':';
  139.   Str(t mod 60:2,tempresult);
  140.   result := result + tempresult;
  141.   For t := 1 to 8 do if result[t] = ' ' then result[t] := '0';
  142.   SecToString := result;
  143. end;
  144.  
  145. Function elapsed_time(start_str, end_str: Datestring): Datestring;
  146. var
  147.   i,j,k,starttime,endtime: integer;
  148. begin
  149.   val(copy(end_str,1,2),i,j);
  150.   endtime := i * 3600;
  151.   val(copy(end_str,4,2),i,j);
  152.   endtime := endtime + (i * 60);
  153.   val(copy(end_str,7,2),i,j);
  154.   endtime := endtime + i;
  155.   val(copy(start_str,1,2),i,j);
  156.   starttime := i * 3600;
  157.   val(copy(start_str,4,2),i,j);
  158.   starttime := starttime + (i * 60);
  159.   val(copy(start_str,7,2),i,j);
  160.   starttime := starttime + i;
  161.   k := endtime - starttime;
  162.   elapsed_time := SecToString(k);
  163. end;
  164.  
  165. Function elapsed_real_time(tempstring: Datestring): real;
  166. var
  167.   temp, temptime : real;
  168.   err            : integer;
  169. begin
  170.   val(copy(tempstring,1,2),temptime,err); {get hours}
  171.   val(copy(tempstring,4,2),temp,err);
  172.   temptime := temptime + (temp/60);       {get fraction of hours from minutes}
  173.   val(copy(tempstring,7,2),temp,err);
  174.   temptime := temptime + (temp/3600);     {get fraction of hours from seconds}
  175.   elapsed_real_time := temptime;
  176. end;
  177.  
  178. Procedure initialize_variables;
  179. begin
  180.   logoff:=false;
  181.   log_data.usage := '@';
  182.   log_data.start_date_log:= Date;
  183.   log_data.start_time_log:= Time;
  184.   log_data.end_time_log:= Time;
  185.   log_data.elapsed_log:= '00:00:00';
  186.   log_data.comment:= '';
  187.   log_data.elapsed_real:=0;
  188. end;
  189.  
  190. Function uppercase(tempstring: CommandString; startpos, number: integer): CommandString;
  191. var temp : CommandString;
  192.     i    : integer;
  193. begin
  194.   if length(tempstring) >= startpos then
  195.   begin
  196.     tempstring:=copy(tempstring,startpos,number);
  197.     for i := 1 to length(tempstring) do
  198.       tempstring[i] := upcase(tempstring[i